using System;
using System.Collections.Generic;

namespace RaisingStudio.SmallBasicCompiler
{
    public class TokenEnumerator
    {
        private List<TokenInfo> _tokenList;
        private int _currentIndex;
        private TokenInfo _current;
        public int LineNumber
        {
            get;
            set;
        }
        public bool IsEndOfList
        {
            get
            {
                return this._currentIndex == this._tokenList.Count;
            }
        }
        public bool IsEndOfNonCommentList
        {
            get
            {
                return this._currentIndex == this._tokenList.Count || this._current.TokenType == TokenType.Comment;
            }
        }
        public TokenInfo Current
        {
            get
            {
                return this._current;
            }
        }
        public TokenEnumerator(List<TokenInfo> tokenList)
        {
            this._tokenList = tokenList;
            if (tokenList.Count > 0)
            {
                this._current = tokenList[0];
            }
        }
        public TokenInfo PeekNext()
        {
            if (this._currentIndex < this._tokenList.Count - 1)
            {
                return this._tokenList[this._currentIndex + 1];
            }
            return TokenInfo.Illegal;
        }
        public bool MoveNext()
        {
            if (this._currentIndex >= this._tokenList.Count)
            {
                return false;
            }
            this._currentIndex++;
            if (this._currentIndex < this._tokenList.Count)
            {
                this._current = this._tokenList[this._currentIndex];
                return true;
            }
            return false;
        }
        public bool StepBack()
        {
            if (this._currentIndex < 0)
            {
                return false;
            }
            this._currentIndex--;
            if (this._currentIndex >= 0)
            {
                this._current = this._tokenList[this._currentIndex];
                return true;
            }
            return false;
        }
        public void Reset()
        {
            this._currentIndex = 0;
            this._current = ((this._currentIndex < this._tokenList.Count) ? this._tokenList[this._currentIndex] : default(TokenInfo));
        }
    }
}
